import {Component, inject, OnInit} from '@angular/core';
import {CommonService} from "../../service/base/common.service";
import {UserHttpService} from "../../service/http/user.http.service";
import {NZ_MODAL_DATA, NzModalRef} from "ng-zorro-antd/modal";
import {HttpCustomConfig} from "../../service/base/base.http.service";
import {ProductHttpService} from "../../service/http/product.http.service";

@Component({
  selector: 'app-product-stock',
  templateUrl: './product-stock.component.html',
  styleUrls: ['./product-stock.component.less']
})
export class ProductStockComponent implements OnInit {

  updateType: string = 'add';
  updateTypeList = [
    {value: 'add', label: '增加库存'},
    {value: 'sub', label: '减少库存'}];
  quantity: number = 0;

  readonly nzModalData: any = inject(NZ_MODAL_DATA);

  constructor(private commonService: CommonService,
              private productHttpService: ProductHttpService,
              private modalRef: NzModalRef) {
  }

  defaultHttpConfig: HttpCustomConfig = {showLoading: false}

  ngOnInit(): void {

  }

  handleConfirm(): void {
    this.productHttpService.updateStock({
      productId: this.nzModalData.productId,
      updateType: this.updateType,
      quantity: this.quantity
    }, this.defaultHttpConfig).subscribe((res) => {
      this.commonService.toast('修改成功');
      this.modalRef.destroy()
    })
  }
}
